/**
 * 
 */
package com.lehecai.core.api.partner;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;

/**
 * 渠道合作商数据接口管理
 * @author He Wang
 *
 */
public class PartnerDataApi extends AbstractApiResultBean {
	
	public static final String QUERY_DATA_API_ID = "dataapi_id";
	public static final String QUERY_AGENT_ID = "agent_id";
	public static final String QUERY_CONTENT_FLAG = "get_content";
	public static final String QUERY_USER_ID = "user_id";
	public static final String QUERY_URL = "url";
	public static final String QUERY_CONTENT = "content";
	public static final String QUERY_DATA_API_NAME = "dataapi_name";
	
	public static final String SET_DATA_API_ID = "dataapi_id";
	public static final String SET_DATA_API_NAME = "dataapi_name";
	public static final String SET_SHOW_RESULT = "show_result";
	public static final String SET_CATEGORY = "show_category";
	public static final String SET_AGENT_ID = "agent_id";
	public static final String SET_TEMPLATE_CONTENT = "template_content";
	public static final String SET_FREQUENCY = "frequency";
	public static final String SET_CHARSET_TYPE = "charset";
	public static final String SET_PHASE = "phaseamount";
	public static final String SET_RESULT_FORMAT = "result_format";
	public static final String SET_STATUS = "status";
	public static final String SET_FILE_NAME = "file_name";
	
	
	private Integer dataApiId;		    //数据项id
	private Long agentId;		    //渠道id
	private String dataApiName;		//数据项名称
	private YesNoStatus showResult;     //显示开奖结果
	private YesNoStatus category;       //分类
	private Date updateTime;            //更新时间
	private String templateContent;		//模板内容
	private Integer frequency;	        //刷新频率
	private String charsetType;         //编码类型
	private Integer phase;              //彩种期数
	private String resultFormat;        //结果格式
	private String resultFormatStart;   //结果格式开始
	private String resultFormatEnd;     //结果格式结束
	private YesNoStatus status;         //状态，是否启用
	private Boolean contentFlag;        //是否获取content值
	private Boolean statusFLag;         //status状态类型
	private String fileName;            //文件名称
	private String previewUrl;          //模板预览路径
	
	public static PartnerDataApi convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		PartnerDataApi partnerDataApi = new PartnerDataApi();
		if (!isNull(object, "dataapi_id")) {
			partnerDataApi.setDataApiId((getInt(object, "dataapi_id")));
		}
		if (!isNull(object, "agent_id")) {
			partnerDataApi.setAgentId(getLong(object, "agent_id"));
		}
		if (!isNull(object, "show_result")) {
			partnerDataApi.setShowResult(YesNoStatus.getItem(getInt(object, "show_result")));
		}
		if (!isNull(object, "show_category")) {
			partnerDataApi.setCategory(YesNoStatus.getItem(getInt(object, "show_category")));
		}
		if (!isNull(object, "dataapi_name")) {
			partnerDataApi.setDataApiName(getString(object, "dataapi_name"));
		}
		if (!isNull(object, "frequency")) {
			partnerDataApi.setFrequency(getInt(object, "frequency"));
		}
		if (!isNull(object, "charset")) {
			partnerDataApi.setCharsetType(getString(object, "charset"));
		}
		if (!isNull(object, "phaseamount")) {
			partnerDataApi.setPhase(getInt(object, "phaseamount"));
		}
		if (!isNull(object, "result_format")) {
			partnerDataApi.setResultFormat(getString(object, "result_format"));
		}
		if (!isNull(object, "update_time")) {
			partnerDataApi.setUpdateTime(getString(object, "update_time") == null ? null : CoreDateUtils.parseDate(getString(object, "update_time"), CoreDateUtils.DATETIME));
		}
		if (!isNull(object, "status")) {
			partnerDataApi.setStatus(YesNoStatus.getItem(getInt(object, "status")));
		}
		if (!isNull(object, "template_content")) {
			partnerDataApi.setTemplateContent(getString(object, "template_content"));
		}
		if (!isNull(object, "file_name")) {
			partnerDataApi.setFileName(getString(object, "file_name"));
		}
		if (!isNull(object, "url")) {
			partnerDataApi.setPreviewUrl(getString(object, "url"));
		}
		return partnerDataApi;
	}
	
	public static List<PartnerDataApi> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<PartnerDataApi> list = new ArrayList<PartnerDataApi>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}


	public void clear() {
		dataApiId = null;
		dataApiName = null;
		contentFlag = null;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setFrequency(Integer frequency) {
		this.frequency = frequency;
	}

	public Integer getFrequency() {
		return frequency;
	}

	public void setPhase(Integer phase) {
		this.phase = phase;
	}

	public Integer getPhase() {
		return phase;
	}

	public void setShowResult(YesNoStatus showResult) {
		this.showResult = showResult;
	}

	public YesNoStatus getShowResult() {
		return showResult;
	}

	public void setResultFormat(String resultFormat) {
		this.resultFormat = resultFormat;
	}

	public String getResultFormat() {
		return resultFormat;
	}

	public void setTemplateContent(String templateContent) {
		this.templateContent = templateContent;
	}

	public String getTemplateContent() {
		return templateContent;
	}

	public void setCharsetType(String charsetType) {
		this.charsetType = charsetType;
	}

	public String getCharsetType() {
		return charsetType;
	}

	public void setStatus(YesNoStatus status) {
		this.status = status;
	}

	public YesNoStatus getStatus() {
		return status;
	}

	public void setContentFlag(Boolean contentFlag) {
		this.contentFlag = contentFlag;
	}

	public Boolean getContentFlag() {
		return contentFlag;
	}

	public void setStatusFLag(Boolean statusFLag) {
		this.statusFLag = statusFLag;
	}

	public Boolean getStatusFLag() {
		if (status != null) {
			if (status.getValue() == YesNoStatus.YES.getValue()) {
				statusFLag = true;
			} else {
				statusFLag = false;
			}
		}
		return statusFLag;
	}

	public void setResultFormatStart(String resultFormatStart) {
		this.resultFormatStart = resultFormatStart;
	}

	public String getResultFormatStart() {
		return resultFormatStart;
	}

	public void setResultFormatEnd(String resultFormatEnd) {
		this.resultFormatEnd = resultFormatEnd;
	}

	public String getResultFormatEnd() {
		return resultFormatEnd;
	}
	
	public void setPreviewUrl(String previewUrl) {
		this.previewUrl = previewUrl;
	}

	public String getPreviewUrl() {
		return previewUrl;
	}

	public void setCategory(YesNoStatus category) {
		this.category = category;
	}

	public YesNoStatus getCategory() {
		return category;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFileName() {
		return fileName;
	}

    public Long getAgentId() {
        return agentId;
    }

    public void setAgentId(Long agentId) {
        this.agentId = agentId;
    }

    public void setDataApiId(Integer dataApiId) {
		this.dataApiId = dataApiId;
	}

	public Integer getDataApiId() {
		return dataApiId;
	}

	public void setDataApiName(String dataApiName) {
		this.dataApiName = dataApiName;
	}

	public String getDataApiName() {
		return dataApiName;
	}

}
